home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / newmarch.zip / CROSSES.C < prev    next >
C/C++ Source or Header  |  1992-09-08  |  4KB  |  123 lines

  1. /* Author:   $Author: jan $
  2.  * File:     $Source: /usr/usrs/jan/desktop/X_Book.boo/programs/RCS/crosses.c,v $
  3.  * Date:     $Date: 1992/09/09 00:09:50 $
  4.  * Revision: $Revision: 1.1 $
  5.  */
  6.  
  7. #include "copyright.h"
  8.  
  9. #include <Xm/PushB.h>  
  10. #include <Xm/RowColumn.h>  
  11.           
  12. char Class_name[] = "Crosses";      
  13. XmString blank, nought, cross;
  14. int turn;     /* 0 = nought, 1 = cross */
  15.           
  16. /* Callback invoked on Arm action when a 
  17. ** button is pressed
  18. */
  19. void 
  20. pushed (w, client_d, call_d)
  21.      Widget w;
  22.      caddr_t client_d, call_d;
  23. {    XmString xmstr;
  24.      char str[8];
  25.      Arg args[16];
  26.      int n;
  27.  
  28.      /* find the current label in the button */
  29.      n = 0;
  30.      XtSetArg (args[n], XmNlabelString, &xmstr); n++;
  31.      XtGetValues (w, args, n);
  32.      
  33.      /* change the label if it is a blank */
  34.      if (XmStringCompare (xmstr, blank))
  35.      {    n = 0;
  36.           if (turn == 0)
  37.                 XtSetArg (args[n], XmNlabelString,
  38.                          nought);
  39.           else  XtSetArg (args[n], XmNlabelString, 
  40.                          cross);
  41.           n++;
  42.           XtSetValues (w, args, n);
  43.  
  44.           /* update the turn */
  45.           turn = (turn + 1) % 2;
  46.      }
  47. }
  48.  
  49. main (argc, argv)         
  50.      int argc;
  51.      char **argv;
  52. {         
  53.      Widget toplevel, button, rowcol; 
  54.      Arg args[16];
  55.      int i, n;
  56.                      
  57.      turn = 0;     /* nought always starts */
  58.      /* set up the XmStrings */
  59.      blank = XmStringCreateLtoR ("    ",
  60.                           XmSTRING_DEFAULT_CHARSET);
  61.                           /* 3 blank spaces */
  62.      nought = XmStringCreateLtoR ("0", 
  63.                           XmSTRING_DEFAULT_CHARSET);
  64.      cross = XmStringCreateLtoR ("X", 
  65.                           XmSTRING_DEFAULT_CHARSET);
  66.  
  67.      /* Initialize the intrinsics    
  68.          with a toplevel widget  */          
  69.      toplevel = XtInitialize (NULL,       /* application
  70.                                              name  */
  71.                             Class_name,   /* class
  72.                                              name */
  73.                              NULL,        /* options */
  74.                            0,           /* number of
  75.                                        options */
  76.                            &argc, argv);  
  77.  
  78.      /* Create a Row Column with the
  79.         following resource values:
  80.              all children the same size (PACK_COLUMN)
  81.              3 columns (numColumns)
  82.              all labels aligned the same way (isAligned)
  83.              all labels centered (ALIGNMENT_CENTER)
  84.      */
  85.      n = 0;
  86.      XtSetArg (args[n], XmNpacking, XmPACK_COLUMN); n++;
  87.      XtSetArg (args[n], XmNnumColumns, 3); n++;
  88.      XtSetArg (args[n], XmNisAligned, True); n++;
  89.      XtSetArg (args[n], XmNentryAlignment, 
  90.                               XmALIGNMENT_CENTER); n++;
  91.      rowcol = XmCreateRowColumn (
  92.                                 toplevel,/* parent */
  93.                                 "rowcol", /* name    */
  94.                                 args,     /* resource
  95.                                             arguments */
  96.                                 n);       /* number of
  97.                                                args  */
  98.  
  99.      /* create 9 pushbutton children of rowcol with 
  100.          blank labels.
  101.          all buttons are given the same name and 
  102.          have the same callback, because we don't
  103.          need to distinguish them at all.
  104.      */
  105.      for (i = 0; i < 9; i++)
  106.      {     n = 0;
  107.           XtSetArg (args[n], XmNlabelString, blank); n++;
  108.           button = XmCreatePushButton (rowcol,
  109.                                   "button", args, n);
  110.           XtAddCallback (button, XmNarmCallback,
  111.                                   pushed, NULL);
  112.           XtManageChild (button);
  113.      }
  114.  
  115.     XtManageChild (rowcol);
  116.                      
  117.           /* display all of the widgets */          
  118.           XtRealizeWidget (toplevel);        
  119.  
  120.           /* enter the main processing loop */     
  121.           XtMainLoop ();
  122. }
  123.